package com.goodwill.androidtest.observer;

import java.util.ArrayList;
import java.util.List;

public class ObservableImpl implements Observable {
    public List<Observer> observers = new ArrayList<>();

    @Override
    public void registerObserver(Observer observer) {
        if (observers != null && !observers.contains(observer)) {
            observers.add(observer);
        }
    }

    @Override
    public void unregisterObserver(Observer observer) {
        if (observers != null && observers.contains(observer)) {
            observers.remove(observer);
        }
    }

    @Override
    public void notifyObservers(String msg) {
        for (Observer observer : observers) {
            observer.update(msg);
        }
    }
}
